package com.bj58.spat.dao.demo;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.bj58.sfft.utility.dao.basedao.DAOBase;
import com.bj58.sfft.utility.dao.basedao.DAOHelper;
import com.bj58.spat.dao.demo.entity.User;

/**
 * DAOHelper.sql 是对IDAO操作的实现，简单ORM，包括依据对象生成sql，根据实体的注解进行ResultSet解析封装对象
 * 
 * 该demo中例举几个常用方法
 */
public class ComplexCase {
	
	static DAOHelper daoHelper;
	
	@Before
	public void init() {
		String url = SimpleCase.class.getClassLoader().getResource(".").getFile();
		try {
			daoHelper = DAOBase.createIntrance(url + "db0.properties");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	@Test
	public void insert() throws Exception {
		User user = new User();
		user.setId(100L);
		user.setUname("zhangsan");
		user.setAge(20);
		Object result = daoHelper.sql.insert(user);
		
		System.out.println(result);
	}
	
	@SuppressWarnings("unchecked")
	@Test
	public void select() throws Exception {
		String columns = "*";
		String condition = "id>1";
		String orderBy = "";
		List<User> users = daoHelper.sql.getListByCustom(User.class, columns, condition, orderBy);
		System.out.println(users);
	}
	
	@Test
	public void delete() throws Exception {
		daoHelper.sql.deleteByID(User.class, 100L);
	}
	
	@After
	public void after() throws Exception {
		delete();
	}


}
